package com.feng.eduservice.controller;


import com.feng.commonutils.R;
import com.feng.eduservice.entity.EduChapter;
import com.feng.eduservice.service.EduChapterService;
import com.feng.eduservice.service.EduSubjectService;
import com.feng.eduservice.vo.course.chapterVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author fengge
 * @since 2023-01-17
 */
@RestController
@RequestMapping("/eduservice/chapter")
@CrossOrigin
public class EduChapterController {
    @Autowired
    private EduChapterService eduChapterService;
    @GetMapping("getChapterVideo/{courseId}")
    public R getChapterVideo(@PathVariable("courseId") String courseId){

        List<chapterVo> chapterVideo = eduChapterService.getChapterVideo(courseId);
        return R.ok().data("list",chapterVideo);
    }

    @PostMapping("addChapter")
    public R addChapter(@RequestBody EduChapter eduChapter){
        return eduChapterService.addChapter(eduChapter);
    }
    @GetMapping("getChapterInfo/{chapterId}")
    public R getChapterInfo(@PathVariable String chapterId){
        EduChapter byId = eduChapterService.getById(chapterId);
        return R.ok().data("chapter",byId);
    }
    @PostMapping("updateChapter")
    public R updateChapter(@RequestBody EduChapter eduChapter){
         eduChapterService.updateById(eduChapter);
         return R.ok();
    }
    //章节里有小节信息不让删除
    @DeleteMapping("{chapterId}")
    public R deleteChapter(@PathVariable String chapterId){
        return eduChapterService.deleteChapter(chapterId);
    }

}

